﻿using AutoMapper;
using J.Model;
using J.ProductSet.Application.Command.ProductSetupCommand;
using MediatR;
using SqlSugar;
using System.Collections.Generic;

namespace J.ProductSet.Application.CommandHandler.ProductSetupCommandHandler
{
    public class ProductSetupPostCommandHandler : IRequestHandler<ProductSetupPostCommand, int>
    {
        private readonly ISqlSugarClient _sqlSugarClient;
        public IMapper _mapper;
        public ProductSetupPostCommandHandler(ISqlSugarClient sqlSugarClient, IMapper mapper)
        {
            _sqlSugarClient = sqlSugarClient;
            _mapper = mapper;
        }
        public async Task<int> Handle(ProductSetupPostCommand request, CancellationToken cancellationToken)
        {
            ProductSetup release = _mapper.Map<ProductSetup>(request);
            return await _sqlSugarClient.Storageable(release).DefaultAddElseUpdate().ExecuteCommandAsync();
            //return _sqlSugarClient.Insertable(release).ExecuteCommandAsync();
            
        }
    }
}
